package com.bjpowernode.springevent.listener;

import cn.hutool.core.date.DateUtil;
import com.bjpowernode.springevent.events.NoticeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class NoticeListener implements ApplicationListener<NoticeEvent> {
    @Async
    @Override
    public void onApplicationEvent(NoticeEvent event) {
        System.out.println(DateUtil.now()+"|NoticeEvent===事件发生了");
        System.out.println(DateUtil.now()+"|NoticeEvent==="+event.getMsg());
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(DateUtil.now()+"|NoticeEvent===事件处理完成");
    }
}
